﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataCoreTechnologies.SqlServer
{
   /// <summary>
   /// Represents a check constraint that is being applied against a column.
   /// </summary>
   public sealed class CheckConstraint
   {
      #region Public
      //Properties
      /// <summary>
      /// A number that uniquely identifies this class instance.
      /// </summary>
      public Guid InstanceId { get; private set; }
      /// <summary>
      /// The column that this check constraint is being applied against.
      /// </summary>
      public Column Column { get; private set; }
      /// <summary>
      /// A title that is used by the database to refer to this check constraint.
      /// </summary>
      public string Name { get; internal set; }
      /// <summary>
      /// The algorithm that is used to validate values in the column this check constraint
      /// is being applied against.
      /// </summary>
      public string Formula { get; internal set; }
      /// <summary>
      /// The date this check constraint was created.
      /// </summary>
      public DateTime CreateDate { get; internal set; }
      /// <summary>
      /// The last time this check constraint was modified.
      /// </summary>
      public DateTime ModifyDate { get; internal set; }
      /// <summary>
      /// Indicates whether this was a system or user created check constraint.
      /// </summary>
      public Boolean IsMicrosoftShipped { get; internal set; }
      /// <summary>
      /// Indicates whether this was published for replication.
      /// </summary>
      public Boolean IsPublished { get; internal set; }
      /// <summary>
      /// Indicates whether this schema was published for replication.
      /// </summary>
      public Boolean IsSchemaPublished { get; internal set; }
      /// <summary>
      /// Indicates whether this check constraint has been disabled.
      /// </summary>
      public Boolean IsDisabled { get; internal set; }
      /// <summary>
      /// Collection of name / value pairs being applied to this check constraint.
      /// </summary>
      public IEnumerable<ExtendedProperty> ExtendedProperties
      {
         get
         {
             for (int index = 0; index < _extendedProperties.Count; index++)
             {
                 yield return _extendedProperties[index];
             }
         }
      }
      #endregion
      #region Internal
      //Constructor
      /// <summary>
      /// Creates an instance of a check constraint and associates it with the column specified by the parameter.
      /// </summary>
      /// <param name="container">The column this check constraint is associated with.</param>
      internal CheckConstraint(Column container)
      {
         InstanceId = System.Guid.NewGuid();
         Column = container;
      }
      //Properties
      /// <summary>
      /// A number that uniquely identifies this check constraint within the database.
      /// </summary>
      internal int Id { get; set; }
      //Methods
      /// <summary>
      /// Associates a extended property with this check constraint.
      /// </summary>
      /// <param name="extendedProperty">The extended property that this check constraint is associated with.</param>
      internal void AddExtendedProperty(ExtendedProperty extendedProperty) { _extendedProperties.Add(extendedProperty); }
      #endregion
      #region Private
      private List<ExtendedProperty> _extendedProperties = new List<ExtendedProperty>();
      #endregion
   }
}
